<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <script src="js/jquery-3.5.1.js"></script>
    <script>
        var time;
        var sec = 60;
        $(function () {
            $.post("findName",function (data) {
                //login=1是未登录 login=0是已登录
                var login = data.loginMsg;
                if (login==1){
                    //未登录
                    $("#msg").html(data.msg);
                    $("#btn").attr("disabled","disabled");
                    $("#btn2").attr("disabled","disabled");
                }else {
                    $("#name").html(data.msg);
                }
            },"json");


            $("#btn").click(function () {
                $("#btn").attr("disabled","disabled");
                time = setInterval(chTime,1000);
                $.post("vifCode");

            });

            $("#btn2").click(function () {
                //提交
                var oldPwd = $("#oldPwd").html();
                var newPwd = $("#newPwd").html();
                var code = $("#code").html();
                $.post("SubmitPwd",{"oldPwd":oldPwd,"newPwd":newPwd,"code":code},function (data) {
                    var msg = data.msg;
                    if (msg != null){
                        $("#msg").html(msg);
                    }else {
                        location.href="shop_index.html";
                    }
                },"json");
            });
        });

        function chTime() {
            var $btn = $("#btn");
            if (sec==0){
                $btn.removeAttr("disabled");
                clearInterval(time);
                $btn.val("点击获取");
                sec = 60;
            }else {
                sec--;
                $btn.val(sec+"s后尝试")
            }
        }



    </script>
    <style>
        div{
            background-color: #1b6d85;
            margin: auto;
            width: 330px;
            height: 170px;
        }
    </style>
</head>
<body>
<div>
    <table>

        <tr>
            <td>名字</td>
            <td><input type="text" disabled="disabled" id="name"></td>
        </tr>
        <tr>
            <td>旧密码</td>
            <td><input type="password" id="oldPwd"></td>
        </tr>
        <tr>
            <td>新密码</td>
            <td><input type="password" id="newPwd"></td>
        </tr>
        <tr>
            <td>验证码</td>
            <td><input type="text" id="code"></td>
            <td><input type="button" value="点击获取" id="btn"></td>
        </tr>
        <tr>
            <td><input type="button" id="btn2" value="提交"></td>
        </tr>
        <tr>
            <td id="msg"></td>
        </tr>
    </table>
</div>
</body>
</html>